package mww.javabean.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import mww.common.ConnectionFactory;
import mww.common.DaoException;
import mww.common.ResourceClose;

import mww.javabean.entity.Admin;

public class AdminDaoImpl implements AdminDao {

	@Override
	public Admin findAdminByLoginName(String loginName) {
		Admin admin=null;
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		try{
			conn=ConnectionFactory.getConnection();
			String sql="select * from admin where loginName=?"; 
			pstmt=conn.prepareStatement(sql);
			pstmt.setString(1, loginName);
			rs=pstmt.executeQuery();
			while(rs.next()){
				admin=new Admin();
				admin.setLoginName(rs.getString(1));
				admin.setName(rs.getString(2));
				admin.setPassword(rs.getString(3));
			}
		}catch (SQLException e) {
			e.printStackTrace();
			throw new DaoException("数据库操作异常，请稍后重试!");
		}finally{
			ResourceClose.close(rs, pstmt, conn);
		}
		return admin;
	}

}
